﻿<script>

    var _shops = @this.RawSerialize(this.ViewBag.ListShop); 
    var _sts = [{ "ID": 0, "Title": "待审核" }, { "ID": 1, "Title": "通过初审" }, { "ID": 2, "Title": "财务审核" }, { "ID": 3,"Title":"仓库审核"}]; 

    var _vm;
    $(function () {
        var vm = new PageViewModel();
        _vm = vm;
        ko.applyBindings(vm);
        vm.init();


    });



    function PageViewModel() {
        var me = this;
        ViewModel.call(me);
        vmExtend.call(me);

        me.url = "/Wiki/ShopOrder/GetItemModels?Id=@ViewBag.Id";
        me.deleteUrl = "/Wiki/ShopOrder/DeleteItem";
        me.dialog = new FormDialog(me);

        me.Refund = function(){
            var OrderID = "@ViewBag.Id";
            $ace.get("/API/PayRefund", { OrderID: OrderID }, function (result)
            {
                if (result.Status == 100) {
                    $ace.msg(result.Data);
                }
            });
        }
         
     }
    function vmExtend() {
        var me = this;
    }

    function FormDialog(vm) {
        var me = this;
        Dialog.call(me);

        me.posts = _oba([]);

        me.onOpen = function () {
            var model = me.editModel();
            if (model) {
                var dataModel = model.Data;
                var bindModel = $ko.toJS(model);
                me.model(bindModel);


            }
            else {
                me.model({});

            }
        }

        me.onSave = function () {
            if (!$('#form1').formValid()) {
                return false;
            }

            var model = me.model();




            if (me.editModel()) {
                $ace.post("/Wiki/ShopOrder/UpdateItem", model, function (result) {
                    $ace.msg(result.Msg);
                    me.close();
                    vm.dataTable.reload();
                }
                );
            }
            else {
                $ace.post("/Wiki/ShopOrder/Add", model, function (result) {
                    $ace.msg(result.Msg);
                    me.close();
                    vm.loadData();
                }
                );
            }
        }
    }
     
</script>
